package itdep.ui.pages.address;

import ga.tapestry.commonlib.base.pages.EntityPage;
import ga.tapestry.internal.SelectModelBuilder;
import itdep.domain.address.Country;
import itdep.domain.address.Region;
import itdep.services.address.CountryService;
import itdep.services.address.RegionService;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.ioc.annotations.Inject;

import java.util.List;

/**
 * @author Ivan Khalopik
 * @version $Revision: 43 $ $Date: 2010-06-25 09:40:26 +0000 (Fri, 25 Jun 2010) $
 */
public class Regions extends EntityPage<Region> {

	@Inject
	private CountryService countryService;

	@Inject
	private RegionService regionService;

	@Inject
	private SelectModelBuilder selectModelBuilder;

	private SelectModel countryModel;

	@Override
	protected RegionService getEntityService() {
		return regionService;
	}

	public SelectModel getCountryModel() {
		if (countryModel == null) {
			final List<Country> countries = countryService.getEntities();
			countryModel = selectModelBuilder.buildFormatted(Country.class, countries, "%s", Country.NAME_PROPERTY);
		}
		return countryModel;
	}
}